﻿// dllmain.cpp : 定义 DLL 应用程序的入口点。
#include "pch.h"

//配置部分
int yourdata = 0;
char ModuleName[MAX_PATH] = "Client Sample";
BOOL IsOn = FALSE;
BYTE KeyCode = 0xFF;
BYTE ReloadKeyCode = 0xFF;

void LoadCFG()
{
	IsOn = cfgload::GetModuleIsOn(ModuleName);
	KeyCode = cfgload::GetModuleHotKey(ModuleName);
	ReloadKeyCode= cfgload::GetModuleHotKey("Reload cfg");
}

void Trigger()
{
	CHAR info[MAX_PATH]="";
	cfgload::GetModuleDescription(ModuleName, info, MAX_PATH);
	if (IsOn)
	{
		IsOn = FALSE;
		D2Functions::GameInfof("$$9Module %s $$0:$$1OFF", info);
	}
	else
	{
		IsOn = TRUE;
		D2Functions::GameInfof("$$9Module %s $$0:$$2ON", info);
	}
}

extern "C"
{
	void __declspec(dllexport) DllGameLoop(GamePub *pGamePub)
	{
		//游戏内的GameLoop
	}

	void __declspec(dllexport) DllGameRunOnce(GamePub* pGamePub)
	{
		LoadCFG();
		//进入房间运行一次
	}

	void __declspec(dllexport)DllGameEnd(GamePub* pGamePub)
	{
		//退出房间时运行一次
	}

	void __declspec(dllexport)DllGamePacketReceived(BYTE* aPacket, DWORD aLength, GamePub* pGamePub)
	{
		//在游戏接受到数据包时处理
	}

	void __declspec(dllexport)DllGameCommandLine(char** argv, int argc, GamePub* pGamePub)
	{
		//游戏内发送.文本处理
	}

	void __declspec(dllexport)DllGamePacketSent(BYTE* aPacket, DWORD aLength, GamePub* pGamePub)
	{
		//在游戏发送数据包时处理
	}

	void __declspec(dllexport)DllGameKeyDown(BYTE keycode, BYTE repeat, GamePub* pGamePub)
	{
		//游戏内按键处理
		if (keycode == 0xFF)return;

		if (keycode == ReloadKeyCode)
		{
			IsOn = FALSE;
			LoadCFG();
		}
		else if (keycode == KeyCode)
		{
			Trigger();
		}
		if (keycode == VK_NUMPAD0)
		{
			
		}
		//添加处理的代码
	}

	void __declspec(dllexport)DllGameDrawClient(GamePub* pGamePub)
	{
		//你可以画一个小猪佩奇
	}

	void __declspec(dllexport)DllGameLoopThread(GamePub* pGamePub)
	{
		//这个比较准时 每0.01秒运行一次
	}
}

BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
                     )
{
    switch (ul_reason_for_call)
    {
    case DLL_PROCESS_ATTACH:
    case DLL_THREAD_ATTACH:
    case DLL_THREAD_DETACH:
    case DLL_PROCESS_DETACH:
        break;
    }
    return TRUE;
}

